<template>
  <x-layout bg-color="#fff">
    <template #common>
      <div class="flex flex-col gap-20rpx p-20rpx">
        <u-subsection
          @change="changeIndex"
          :list="list"
          :current="current"
          active-color="#f56c6c"
        />
        <u-textarea
          v-model="curValue"
          placeholder="请输入内容"
          count
          height="120"
        />
        <u-button text="转换" color="#0ab99c" @click="changeValueHandle" />
        <u-textarea
          v-if="changeValue"
          v-model="changeValue"
          count
          height="120"
          disabled
        />
        <u-button
          v-if="changeValue"
          text="复制"
          color="#5ac725"
          plain
          @click="copyLink"
        />
      </div>
    </template>
  </x-layout>
</template>

<script setup>
import { ref } from 'vue'
const current = ref(0)

const changeIndex = (idx) => {
  current.value = idx
}

const curValue = ref('')
const changeValue = ref('')

const list = ref(['迅雷', '其他'])

const rules = [
  'magnet:?xt=urn:btih:',
  'none:'
]

const changeValueHandle = () => {
  changeValue.value = rules[current.value] + curValue.value
}

const copyLink = () => {
  uni.setClipboardData({
    data: changeValue.value || '',
    success (res) {
      uni.getClipboardData({
        success (res) {
          uni.showToast({
            title: '复制成功'
          })
        }
      })
    }
  })
}
</script>

<style lang="scss" scoped>

</style>
